from wordcloud import WordCloud
import jieba
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
plt.rcParams['font.family']=['FangSong']

text = open("resource/十九大内容节选.txt", encoding='utf-8').read().replace("的", "").replace("和", "") # 读取内容
# wc = WordCloud().generate(text=text) # 英文分词
text = ' '.join(jieba.cut(text)) # 中文分词
mask = np.array(Image.open("resource/党徽.png")) # 生成图片模板
wc = WordCloud(mask=mask, font_path='resource/STXINWEI.TTF', width=800, height=600, mode='RGBA', background_color=None).generate(text)
plt.imshow(wc, interpolation='bilinear')
plt.axis('off')
plt.title("十九大内容节选词云图")
plt.show()